package com.sxpi.controller;

import com.sxpi.common.result.Result;
import com.sxpi.model.entity.WorkImages;
import com.sxpi.model.entity.Works;
import com.sxpi.model.vo.WorksVo;
import com.sxpi.service.WorkImagesService;
import com.sxpi.service.WorksService;
import com.sxpi.utils.FileUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/works")

public class WorksController {
    @Resource
    private WorksService worksService;
    ///上传文件路径
    @Value("${uploadFile.path}")
    private String uploadDir;


    @GetMapping("/getAllWorks")
    public Result<List<WorksVo>> getAllWorks(
            @RequestParam(required = false) Long worksId,
            @RequestParam(required = false) Long userId) {
        List<WorksVo> worksVoList = worksService.getAllWorks(worksId,userId);
        return Result.ok(worksVoList);
    }

    /**
     *
     * 新增作品
     * @param files
     * @param userId
     * @param title
     * @param description
     * @return
     */

    @PostMapping("/addWorks")
        public Result<Boolean> addWorks(@RequestParam("files") List<MultipartFile> files, @RequestParam Long userId, @RequestParam String title, @RequestParam String description) {

         Boolean save = worksService.addWorks(files, userId, title, description);
        return Result.ok(save);
        }
}